package com.fita.admin.service.report.impl;

import com.demo2do.core.entity.page.Page;
import com.demo2do.core.persistence.support.QueryBuilder;
import com.fita.admin.entity.search.TransactionRecordSearch;
import com.fita.admin.service.DataServiceImpl;
import com.fita.admin.service.report.TransactionRecordService;
import com.fita.entity.wallet.TransactionRecord;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * @description:
 * @author: 11200
 * @date: 2019/7/29
 */
@Service("transactionRecordService")
public class TransactionRecordServiceImpl extends DataServiceImpl<TransactionRecord> implements TransactionRecordService {

    /**
     * @param queryBuilder
     * @return
     */
    public int count(QueryBuilder queryBuilder) {

        String sentence = "SELECT COUNT(*) " + queryBuilder.buildSentenceTemplate();
        Map<String, Object> params = queryBuilder.buildParameters();
        int totals = genericDaoSupport.searchForInt(sentence, params);
        return totals;
    }

    /**
     *
     * @param search
     * @param page
     * @return
     */
    public List<TransactionRecord> search(TransactionRecordSearch search, Page page) {

        String sentence = "SELECT tr " + search.buildSentenceTemplate();
        Map<String, Object> params = search.buildParameters();
        List result = genericDaoSupport.searchForList(sentence, params, page.getBeginIndex(), page.getEveryPage());
        page.calculate();
        return result;
    }
}
